<?php
/**
 * WpSimpleConsole.php
 * 
 * This file contains the WpSimpleConsole class which simply prints out the text
 * @author Robert Schmidt <robert@wildpack.de>
 * @version 1.0
 * @package wildpack
 * @subpackage base.console
 */

/**
 * The WpConsole interface to implement
 */
require_once(dirname(__FILE__).'/IWpConsole.php');

/**
 * A simple wrapper for the print() function
 * 
 * A simple console which uses the print() command to output the text
 * 
 * <code>
 * $csl = new WpSimpleConsole(true);
 * $csl->write('Writing to console');
 * $csl->write('Writing to console again');
 * 
 * // Will print the following
 * 1. Writing to console
 * 2. Writing to console again
 * </code>
 * 
 * @author Robert Schmidt <robert@wildpack.de>
 * @version 1.0
 * @package wildpack
 * @subpackage base.console
 */
class WpSimpleConsole implements IWpConsole 
{
  /**
   * Determines wether to print linenumbers or not
   */
	public $LineNumbers = false;
  
  /**
   * The counter for the line numbers
   */
	private $line = 0;
	
	/**
   * The class constructor
   * @param bool $linenumbers True to show line numbers false else
   */
	function __construct($linenumbers=false)
	{
		$this->LineNumbers = $linenumbers;
	}
	
	/**
   * Writes text to the console
   * @param string $msg The text to write to the console
   */
	function write($msg)
	{
		if ($this->LineNumbers === true) {
			printf("%4u ", $this->line++);
		}
		
		print($msg."\n");
	}
}

/* End of file WpSimpleConsole.php */
/* Location: ./wildpack/base/console/WpSimpleConsole.php */ 
